#region License

// Copyright (c) 2013, ClearCanvas Inc.
// All rights reserved.
// http://www.clearcanvas.ca
//
// This file is part of the ClearCanvas RIS/PACS open source project.
//
// The ClearCanvas RIS/PACS open source project is free software: you can
// redistribute it and/or modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// The ClearCanvas RIS/PACS open source project is distributed in the hope that it
// will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
// Public License for more details.
//
// You should have received a copy of the GNU General Public License along with
// the ClearCanvas RIS/PACS open source project.  If not, see
// <http://www.gnu.org/licenses/>.

#endregion

// This file is auto-generated by the ClearCanvas.Model.SqlServer.CodeGenerator project.

namespace ClearCanvas.ImageServer.Model
{
    using System;
    using System.Xml;
    using ClearCanvas.Enterprise.Core;
    using ClearCanvas.ImageServer.Enterprise;
    using ClearCanvas.ImageServer.Enterprise.Command;
    using ClearCanvas.ImageServer.Model.EntityBrokers;

    [Serializable]
    public partial class Device: ServerEntity
    {
        #region Constructors
        public Device():base("Device")
        {}
        public Device(
             Boolean _dhcp_
            ,Boolean _enabled_
            ,Boolean _allowStorage_
            ,Boolean _acceptKOPR_
            ,Boolean _allowRetrieve_
            ,Boolean _allowQuery_
            ,Boolean _allowAutoRoute_
            ,Int16 _throttleMaxConnections_
            ,DateTime _lastAccessedTime_
            ,DeviceTypeEnum _deviceTypeEnum_
            ,ServerEntityKey _serverPartitionKey_
            ,String _aeTitle_
            ,Int32 _port_
            ,String _description_
            ,String _ipAddress_
            ):base("Device")
        {
            Dhcp = _dhcp_;
            Enabled = _enabled_;
            AllowStorage = _allowStorage_;
            AcceptKOPR = _acceptKOPR_;
            AllowRetrieve = _allowRetrieve_;
            AllowQuery = _allowQuery_;
            AllowAutoRoute = _allowAutoRoute_;
            ThrottleMaxConnections = _throttleMaxConnections_;
            LastAccessedTime = _lastAccessedTime_;
            DeviceTypeEnum = _deviceTypeEnum_;
            ServerPartitionKey = _serverPartitionKey_;
            AeTitle = _aeTitle_;
            Port = _port_;
            Description = _description_;
            IpAddress = _ipAddress_;
        }
        #endregion

        #region Public Properties
        [EntityFieldDatabaseMappingAttribute(TableName="Device", ColumnName="Dhcp")]
        public Boolean Dhcp
        { get; set; }
        [EntityFieldDatabaseMappingAttribute(TableName="Device", ColumnName="Enabled")]
        public Boolean Enabled
        { get; set; }
        [EntityFieldDatabaseMappingAttribute(TableName="Device", ColumnName="AllowStorage")]
        public Boolean AllowStorage
        { get; set; }
        [EntityFieldDatabaseMappingAttribute(TableName="Device", ColumnName="AcceptKOPR")]
        public Boolean AcceptKOPR
        { get; set; }
        [EntityFieldDatabaseMappingAttribute(TableName="Device", ColumnName="AllowRetrieve")]
        public Boolean AllowRetrieve
        { get; set; }
        [EntityFieldDatabaseMappingAttribute(TableName="Device", ColumnName="AllowQuery")]
        public Boolean AllowQuery
        { get; set; }
        [EntityFieldDatabaseMappingAttribute(TableName="Device", ColumnName="AllowAutoRoute")]
        public Boolean AllowAutoRoute
        { get; set; }
        [EntityFieldDatabaseMappingAttribute(TableName="Device", ColumnName="ThrottleMaxConnections")]
        public Int16 ThrottleMaxConnections
        { get; set; }
        [EntityFieldDatabaseMappingAttribute(TableName="Device", ColumnName="LastAccessedTime")]
        public DateTime LastAccessedTime
        { get; set; }
        [EntityFieldDatabaseMappingAttribute(TableName="Device", ColumnName="DeviceTypeEnum")]
        public DeviceTypeEnum DeviceTypeEnum
        { get; set; }
        [EntityFieldDatabaseMappingAttribute(TableName="Device", ColumnName="ServerPartitionGUID")]
        public ServerEntityKey ServerPartitionKey
        { get; set; }
        [EntityFieldDatabaseMappingAttribute(TableName="Device", ColumnName="AeTitle")]
        public String AeTitle
        { get; set; }
        [EntityFieldDatabaseMappingAttribute(TableName="Device", ColumnName="Port")]
        public Int32 Port
        { get; set; }
        [EntityFieldDatabaseMappingAttribute(TableName="Device", ColumnName="Description")]
        public String Description
        { get; set; }
        [EntityFieldDatabaseMappingAttribute(TableName="Device", ColumnName="IpAddress")]
        public String IpAddress
        { get; set; }
        #endregion

        #region Static Methods
        static public Device Load(ServerEntityKey key)
        {
            using (var context = new ServerExecutionContext())
            {
                return Load(context.ReadContext, key);
            }
        }
        static public Device Load(IPersistenceContext read, ServerEntityKey key)
        {
            var broker = read.GetBroker<IDeviceEntityBroker>();
            Device theObject = broker.Load(key);
            return theObject;
        }
        static public Device Insert(Device entity)
        {
            using (var update = PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush))
            {
                Device newEntity = Insert(update, entity);
                update.Commit();
                return newEntity;
            }
        }
        static public Device Insert(IUpdateContext update, Device entity)
        {
            var broker = update.GetBroker<IDeviceEntityBroker>();
            var updateColumns = new DeviceUpdateColumns();
            updateColumns.Dhcp = entity.Dhcp;
            updateColumns.Enabled = entity.Enabled;
            updateColumns.AllowStorage = entity.AllowStorage;
            updateColumns.AcceptKOPR = entity.AcceptKOPR;
            updateColumns.AllowRetrieve = entity.AllowRetrieve;
            updateColumns.AllowQuery = entity.AllowQuery;
            updateColumns.AllowAutoRoute = entity.AllowAutoRoute;
            updateColumns.ThrottleMaxConnections = entity.ThrottleMaxConnections;
            updateColumns.LastAccessedTime = entity.LastAccessedTime;
            updateColumns.DeviceTypeEnum = entity.DeviceTypeEnum;
            updateColumns.ServerPartitionKey = entity.ServerPartitionKey;
            updateColumns.AeTitle = entity.AeTitle;
            updateColumns.Port = entity.Port;
            updateColumns.Description = entity.Description;
            updateColumns.IpAddress = entity.IpAddress;
            Device newEntity = broker.Insert(updateColumns);
            return newEntity;
        }
        #endregion
    }
}
